<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests;
use Cache, Auth, Hash;
use App\User;

class ConfigController extends Controller
{

    public function __construct()
    {
        parent::__construct();
        view()->share([
            '_xSystem' => 'am-in',

        ]);
    }

    public function password()
    {

        return view('Admin.xHotel.config.password')->with('_password', 'am-active');;
    }

    function update_password(Request $request)
    {
        $admin = Auth::user();
        if (!Hash::check($request->old_password, $admin->password)) {
            return back()->with('error', '原始密码错误~');
        }
        $this->validate($request, [
            'old_password' => 'required',
            'password' => 'required|min:6|confirmed',
        ]);
        $admin = User::find($admin->id);
        $admin->fill(['password' => bcrypt($request->password)])->save();
        return redirect('/logout')->with('success', '修改成功~');
    }
}
